<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div >
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">上架任务</label>
                            <div class="layui-input-inline">
                                <select name="taskid" id="taskid" lay-verify="" lay-search="">
                                    <option value=""> -所有任务- </option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">是否上架</label>
                            <div class="layui-input-inline">
                                <select name="enable" lay-verify="" lay-search="">
                                    <option value=""> -所有- </option>
                                    <option value="Y">是</option>
                                    <option value="N">否</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">SKU状态</label>
                            <div class="layui-input-inline">
                                <select name="zt" lay-verify="" lay-search="">
                                    <option value=""> -所有状态- </option>
                                    <option value="0">等待预处理</option>
                                    <option value="8">等待上架</option>
                                    <option value="1">上架成功</option>
                                    <option value="2">上架失败</option>
                                    <option value="3">状态异常</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">上架类目</label>
                            <div class="layui-input-inline">
                                <input type="text" name="catename" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">上架品牌</label>
                            <div class="layui-input-inline">
                                <input type="text" name="brandname" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>



        <table class="layui-hide" id="shelvestasksTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>

<script>
    layui.use(['form', 'table','miniPage','element', 'util'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage,
            util = layui.util;




        $.post("common/shelvestasks", {page: 1, limit: 10000}, function (res) {
            if ( res.code == 0 ) {
                var content = [];
                $.each(res.data, function (i, val) {
                    content.push('<option value="' + val["id"] + '">' + val["name"] + '</option>');
                });
                console.log(content.join(" "));
                var s = $('#taskid');
                s.html(content);
                console.log(s.html());
                form.render('select'); ///重新渲染select#chapterId
            } else {
                layer.msg(res.message);
            }
        });


        form.render();


        var map = {
            302: "待采销审核",
            304: "待产品审核",
            306: "<span style='color: green'>审核通过</span>",
            303: "采销驳回",
            305: "产品驳回",
            309: "待经理审核",
            310: "经理驳回",
            311: "待总监审核",
            312: "总监驳回",
            313: "待质量管理部审核",
            320: "质量管理部驳",
            321: "待质量负责人审核",
            322: "质量负责人驳回",
            "null": ""
        };

        table.render({
            elem: '#shelvestasksTableId',
            url: 'common/shelvesitems',

            cols: [[
                {field: 'id', width: 240, title: 'ID', hide: true},
                {field: 'skucode', width: 140, title: 'SKU编码'},
                {field: 'jdskuname', width: 280, title: 'SKU名称'},
                {field: 'cidName1', width: 160, title: '上架类目'},
                {field: 'brandName', width: 160, title: '上架品牌'},
                {field: 'enable', width: 120, title: '是否上架', templet: function (d) {
                        if ( !!d["enable"] &&  d["enable"]==='Y' ) {
                            return '<span style="color: green">是</span>';
                        }
                        return '否';
                    }
                },
                {field: 'zt', width: 100, title: '状态',templet: function (d) {
                        return  {"0": "等待预处理","8": "等待上架", "3": "状态异常", "1": "<span style='color: green'>上架成功</span>", "2": "<span style='color: red'>上架失败</span>"}[d.zt] || '<span style="color: yellow">' + d.zt + '</span>';
                    }
                },
                {field: 'state', width: 120, title: '审核状态', templet: function (d) {
                        if ( d["state"] == undefined ) {
                            return "";
                        }
                        return  map[d["state"]] || '<span style="color: red">' + d["state"]||"" + '</span>';
                    }
                },
                {field: 'reject', width: 120, title: '是否驳回', templet: function (d) {
                        if ( !!d["reject"] ) {
                            return '<span style="color: red">驳回</span>';
                        }
                        return "";
                    }
                },
                {field: 'opinion', width: 200, title: '审核意见'},
                {field: 'approvetime', title: '审核时间', width: 180, templet : "<div>{{layui.util.toDateString(d.approvetime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {field: 'cate4', width: 160, title: '原始类目'},
                {field: 'brand', width: 160, title: '原始品牌'},
                {field: 'model', width: 160, title: '制造商型号'},
                {field: 'deliverydate', width: 140, title: '预计发货日'},
                {field: 'message', width: 240, title: '提示'}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('shelvestasksTableId', {
                page: { curr: 1 },
                where: data.field
            }, 'data');
            return false;
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

    });
</script>